/******************** (C) COPYRIGHT 2010 NXP Semiconductors************
* File Name          : main.c
* Author             : NXP Semiconductors
* Date First Issued  : 01/18/2010
* Description        : Main program body.
*******************************************************************************
*******************************************************************************
* History:
* 01/18/2010		 : V1.0		   initial version
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include <stdio.h>
#include "LPC11xx.h"
#include "gpio.h"

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define SYSTICK_DELAY		5000

/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
volatile uint32_t TimeTick = 0;

/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/* SysTick interrupt happens every 10 ms */
void SysTick_Handler(void)
{
  TimeTick++;
}

/**
  * @brief   delaySysTick function
  * @param   tick	-- lelve
  * @retval None
  */
void delaySysTick(uint32_t tick)
{
  uint32_t timetick;

  /* Clear SysTick Counter */
  SysTick->VAL = 0;
  /* Enable the SysTick Counter */
  SysTick->CTRL |= SYSTICK_ENABLE;

  timetick = TimeTick;
  while ((TimeTick - timetick) < tick);
  
  /* Disable SysTick Counter */
  SysTick->CTRL &= ~SYSTICK_ENABLE;
  /* Clear SysTick Counter */
  SysTick->VAL = 0;
  return;
}
/**
  * @brief   Main program
  * @param  None
  * @retval None
  */
int main (void)
{
  SystemInit();

  /* Called for system library in core_cm0.h. */
  SysTick_Config( SYSTICK_DELAY );
  
  /* Enable AHB clock to the GPIO domain. */
  LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6);
  
  /* Set port 2_0 to output */
  GPIOSetDir( 2, 9, 1 );
  /* Loop forever */
  while (1)                                
  {
	delaySysTick(SYSTICK_DELAY);
	/* LED turn on */
	GPIOSetValue( 2, 9, 0 );
	delaySysTick(SYSTICK_DELAY);
	/* LED turn off */
	GPIOSetValue( 2, 9, 1 );
  }
}  


/**
  * @}
  */ 

/**
  * @}
  */ 

/************* (C) COPYRIGHT 2010 NXP Semiconductors*****END OF FILE****/
